<template>
<div style="width: 70%;margin-top: 5%">
  <el-form :model="ruleForm"
           :rules="rules"
           ref="ruleForm"
           label-width="100px"
           class="demo-dynamic" >
    <el-form-item
      style="width: 49%"
      label="昵称"
      prop="name"
      :rules="[
          { required: true, message: '请注意昵称长度在1~15个字符', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]"

    >
      <el-input v-model="ruleForm.name"></el-input>
    </el-form-item>
    <br>
    <el-form-item label="性别" prop="region">
      <el-select v-model="ruleForm.sex" placeholder="请选择性别">
        <el-option label="男" value="boy"></el-option>
        <el-option label="女" value="girl"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item
      style="width: 49%"
      label="地址"
      prop="city"
      :rules="[
          { required: true, message: '请注意长度在3~20个字符', trigger: 'blur' },
          { min: 3, max: 20, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]"

    >
      <el-input v-model="ruleForm.city"></el-input>
    </el-form-item>

    <el-form-item
      style="width: 60%"
      label="手机号"
      prop="tel"
      :rules="[
      { required: true, message: '请输入手机号', trigger: 'blur' },
      { type: 'tel', message: '请输入正确的手机号', trigger: ['blur', 'change'] }
    ]"
    >
      <el-input v-model="ruleForm.email"></el-input>
    </el-form-item>

    <el-form-item
      style="width: 80%;height: 120px"
      label="其他"
      prop="motto"
      :rules="[
          { required: false, message: '请输入信息', trigger: 'blur' },
          { min: 0, max: 150, message: '请注意长度不能超过150个字符', trigger: 'blur' }
        ]"

    >
      <el-input type="textarea" style="height: 100px;resize: none" v-model="ruleForm.motto"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="success" @click="submitForm('ruleForm')">提交修改</el-button>

    </el-form-item>
  </el-form>
</div>
</template>

<script>
import emitter from '@/utils/eventbus'
// import { useRouter } from 'vue-router'
export default {
  name: 'changeMsg',
  data () {
    return {
      ruleForm: {
        name: '',
        sex: '女',
        tel: '',
        city: '',
        motto: ''

      }
    }
  },
  methods: {
    submitForm (ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          alert('确认修改!')
          emitter.emit('aMsg', this.ruleForm)
          // const router = useRouter()
          // router.push({ path: '/bokelist' })
          console.log('emit', this.ruleForm)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }

  }

}
</script>

<style scoped>
</style>
